package com.nx.qwr;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

import java.io.IOException;


/**
 * @Author: Qingwr
 * @Date: 2022/8/14 16:51
 * @Description 流量统计入口
 */
public class FlowJobMain {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException, IOException {

        //创建job
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration, "FlowTotal");

        //设置源文件路径
        job.setInputFormatClass(TextInputFormat.class);
        TextInputFormat.addInputPath(job, new Path(args[0]));

        //设置Mapper
        job.setMapperClass(FlowCountMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        //设置Reducer
        job.setReducerClass(FlowCountReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        //设置输出路径
        job.setOutputFormatClass(TextOutputFormat.class);
        TextOutputFormat.setOutputPath(job, new Path(args[1]));

        //执行
        boolean b = job.waitForCompletion(true);
        System.out.println(b ? 0 : 1);
    }
}
